package com.sporadic.backstage.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sporadic.backstage.entity.DishesType;
import com.sporadic.backstage.mapper.DishesTypeMapper;
import com.sporadic.backstage.service.DishesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishesTypeServiceImpl implements DishesTypeService {
    @Autowired
    private DishesTypeMapper dishestypeMapper;
    /**
     * 查询商家所有菜品类型
     * @param merchantId 商家编号
     * @return 类型信息集合
     */
    @Override
    public List<DishesType> selDishesTypeAlL(Integer merchantId) {
        return dishestypeMapper.selDishesTypeAlL(merchantId);
    }

    /**
     * 添加指定商家菜品类型
     * @param dishestype 菜品类型信息
     * @return 受影响行数 大于0添加成功 否则失败
     */
    @Override
    public Integer addDishesType(DishesType dishestype) {
        return dishestypeMapper.insert(dishestype);
    }

    /**
     * 删除指定商家菜品指定类型
     * @param merchantId 商家编号
     * @return 受影响行数 大于0删除成功 否则失败
     */
    @Override
    public Integer delDishesType(Integer merchantId,Integer dtId) {
        QueryWrapper<DishesType> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("dt_id",dtId);
        return dishestypeMapper.delete(queryWrapper);
    }

    /**
     * 根据商家编号修改指定商家菜品类型
     * @param dishestype
     * @return
     */
    @Override
    public Integer upDishesType(DishesType dishestype) {
        QueryWrapper<DishesType> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("dt_id",dishestype.getDtId());
        queryWrapper.eq("dt_merchantId",dishestype.getDtMerchantId());
        return dishestypeMapper.update(dishestype,queryWrapper);
    }

    @Override
    public IPage<DishesType> selDishesType(Page page, Integer merchantId) {
        return dishestypeMapper.selDishesType(page,merchantId);
    }
}
